package cn.com.aiouyi.dao.impl;

import cn.com.aiouyi.dao.ArticleClassDao;
import cn.com.aiouyi.entity.ArticleClass;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.persistence.NoResultException;

/**
 * Dao - 文章分类
 * @author tommy
 *
 */
@Repository("articleClassDaoImpl")
public class ArticleClassDaoImpl extends BaseDaoImpl<ArticleClass, Long> implements ArticleClassDao{

    @Override
    public ArticleClass findExist(String name) {
        if (StringUtils.isEmpty(name)) {
            return null;
        }
        try {
            String jpql = "select articleClass from ArticleClass articleClass where lower(articleClass.name) = lower(:name)";
            return entityManager.createQuery(jpql, ArticleClass.class).setParameter("name", name).getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }
}
